package view.client;

import control.client.DeleteTopicsAction;
import control.client.ListTopicsAction;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTable;
import util.EPanelTypes;
import util.IConstant;

/**
 *
 * @author S3224743
 */
public class TopicPanel extends javax.swing.JPanel
{
    //private static fields
    private static TopicPanel topics;

    //private fields
    private BaseClient baseClient;
    private ListTopicsAction listTopicsAction;
    private DeleteTopicsAction deleteTopicsAction;
    private JComboBox deleteCmbBox;

    //private constructor
    public TopicPanel(BaseClient baseClient)
    {
        this.initComponents();

        //Initialized
        this.baseClient=baseClient;
        this.listTopicsAction=new ListTopicsAction(this);
        this.deleteTopicsAction = new DeleteTopicsAction(this);

        //topicsTable
        this.topicsTable.getSelectionModel().addListSelectionListener(this.listTopicsAction);
        this.topicsTable.addMouseMotionListener(this.listTopicsAction);

        //deleteTopicBtn
        this.deleteTopicBtn.setActionCommand(IConstant.DELETE_TOPIC_BUTTON);
        this.deleteTopicBtn.addActionListener(this.deleteTopicsAction);
    }//end of public Topics(BaseClient baseClient)

    //public static methods
    public static TopicPanel getInstance(BaseClient baseClient)
    {
        if(topics==null)
            topics=new TopicPanel(baseClient);
        return topics;
    }

    //properties
    public JComboBox getDeleteCmbBox()
    {
        return deleteCmbBox;
    }

    public JButton getDeleteTopicBtn()
    {
        return deleteTopicBtn;
    }

    public BaseClient getBaseClient()
    {
        return baseClient;
    }

    public JTable getTopicsTable()
    {
        return topicsTable;
    }



    //public methods
    public void showNorthPanel(EPanelTypes ePanelTypes)
    {
        switch(ePanelTypes)
        {
            case ADMIN:
                this.northPanel.setSize(new Dimension(0,60));
                this.northPanel.setPreferredSize(new Dimension(0,60));
                break;
            default:
                this.northPanel.setSize(new Dimension(0,0));
                this.northPanel.setPreferredSize(new Dimension(0,0));
                break;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        northPanel = new javax.swing.JPanel();
        deleteTopicBtn = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        topicsTable = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout(20, 20));

        northPanel.setMaximumSize(new java.awt.Dimension(32767, 60));
        northPanel.setMinimumSize(new java.awt.Dimension(100, 5));
        northPanel.setPreferredSize(new java.awt.Dimension(791, 60));

        deleteTopicBtn.setText("Delete");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setText("Select topic(s)  and click delete button");

        javax.swing.GroupLayout northPanelLayout = new javax.swing.GroupLayout(northPanel);
        northPanel.setLayout(northPanelLayout);
        northPanelLayout.setHorizontalGroup(
            northPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, northPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(deleteTopicBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31))
        );
        northPanelLayout.setVerticalGroup(
            northPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(northPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(northPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteTopicBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 38, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );

        add(northPanel, java.awt.BorderLayout.PAGE_START);

        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));

        topicsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "", "Topic", "Posted by:", "Date: "
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(topicsTable);
        topicsTable.getColumnModel().getColumn(0).setResizable(false);
        topicsTable.getColumnModel().getColumn(0).setPreferredWidth(10);
        topicsTable.getColumnModel().getColumn(1).setResizable(false);
        topicsTable.getColumnModel().getColumn(2).setResizable(false);
        topicsTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        topicsTable.getColumnModel().getColumn(3).setResizable(false);
        topicsTable.getColumnModel().getColumn(3).setPreferredWidth(50);

        jPanel2.add(jScrollPane1);

        add(jPanel2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton deleteTopicBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel northPanel;
    private javax.swing.JTable topicsTable;
    // End of variables declaration//GEN-END:variables
}
